package com.itheima.controller;

import com.itheima.pojo.Log;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.LogService;
import jakarta.annotation.Resource;
import org.apache.commons.io.IOUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.InputStream;
import java.util.List;
import java.util.stream.Collectors;

@RestController
public class LogController {
    @Resource
    LogService logService;

//    @GetMapping("/log/page")
//    private Result list(){
//        //1. 加载log.txt文件数据
//        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("log.txt");
//        List<String> lines = IOUtils.readLines(inputStream, "UTF-8");
//
//        //2. 对原始数据进行处理 , 组装日志数据
//        List<Log> logList = lines.stream().map(line -> {
//            String[] parts = line.split(",");
//            Log log = new Log(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], parts[6]);
//            return log;
//        }).collect(Collectors.toList());
//
//        //3. 响应结果
//        return Result.success(new PageBean(10L, logList));
//    }

    @GetMapping("/log/page")
    private Result list(@Param("page") Integer page,@Param("pageSize") Integer pageSize){
        return logService.getAll(page,pageSize);
    }

}
